<?php

class data_rules {
	function mapping_exists( $table_1, $key_1, $table_2, $key_2 ) {
		/* Structure of status array
		 * 		1. Bool : Table 1 - Key 1 is linked with atleast 1 in table 2 - key 2
		 * 		2. mixed: items that are not mapped
		 * 		3. Bool : Table 1 - Key 1 is linked with atleast 1 in table 2 - key 2
		 * 		4. mixed: items that are not mapped
		 * */
		$status = array();
		
		$col_1 = array();
		$col_2 = array();
		
		foreach ($table_1 as $row) {
			
			//extract items into array
			$col_1[] = $row[$key_1];
			
		}
		
		foreach ( $table_2 as $row ) {
			
			//extract items into array
			$col_2[] = $row[$key_2];
			
		}
		
		foreach ( $col_1 as $item ) {
			
			if ( !array_search($item, $col_2) ) {
				//Mapping doesn't exists
				$status[0] = true;
				$status[1][] = $item;
			}	
			
		}
		
		foreach ( $col_1 as $item ) {
			
			if ( !array_search($item, $col_2) ) {
				//Mapping doesn't exists
				$status[0] = true;
				$status[1][] = $item;
			}	
			
		}
		
		return $status;
	}
}

?>